package com.douglasalipio.model;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.douglasalipio.entity.PlacesAutocompleteList;
import com.douglasalipio.entity.PlacesAutocompleteList.PlaceAutoComplete;
import com.douglasalipio.service.PlacesService;

public class AutocompleteModel {

	private PlacesService placeService;

	/**
	 * Retrieve pleces by reference.
	 * 
	 * @param reference
	 * @return
	 * @throws IOException
	 */
	public List<String> getPlaces(String reference) throws IOException {

		List<String> placesToAdapter = new ArrayList<String>();

		placeService = new PlacesService();

		PlacesAutocompleteList places = placeService.searchAddress(reference);

		for (PlaceAutoComplete place : places.predictions) {

			placesToAdapter.add(place.description);

		}
		return placesToAdapter;

	}

}
